<template>
    <view class="columnbox wdh-100 content">
        <u--form class="wdh-100" labelPosition="top" :model="form" :rules="rules" ref="uForm">
            <view class="columnbox wdh-100 info-box">
                <view class="wdh-100 title">模版标题</view>
                <u-form-item label=" " prop="name">
                    <input v-model="form.name" placeholder="请输入标题" class="input-box" />
                </u-form-item>
            </view>
            <view class="columnbox wdh-100 info-box">
                <u-form-item label=" " prop="title" class="wdh-100">
                    <textarea v-model="form.title" class="input-box" placeholder="请输入内容"></textarea>
                </u-form-item>
            </view>
        </u--form>
        <view class="wdh-100" style="height: 170rpx;"></view>
        <view class="bottom-box wdh-100 rowbox ">
            <view v-if="submitflag" class="rowbox send-btn wdh-100" style="background: #f6f7fb;color:  #96949e;">
                保存
            </view>
            <view v-else class="rowbox send-btn wdh-100" @click="submitInfo">
                保存
            </view>
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                form: {
                    name: '',
                    title: ''
                },
                rules: {
                    'name': {
                        type: 'string',
                        required: true,
                        message: '请填写标题',
                        trigger: ['blur', 'change']
                    },
                    'title': {
                        type: 'string',
                        required: true,
                        message: '请填写内容',
                        trigger: ['blur', 'change']
                    },
                },
                submitflag: false
            };
        },
        methods: {
            submitInfo() {
                this.$refs.uForm.validate().then(res => {
                    if (!this.submitflag) {
                        uni.showLoading({
                            title: '正在保存'
                        })
                        this.submitflag = true
                        this.$req.post('/doctor/chuliyijianadd', {
                            doctorid: uni.getStorageSync('uid'),
                            name: this.form.name,
                            title: this.form.title
                        }).then(res => {
                            uni.hideLoading()
                            this.submitflag = false
                            let pages = getCurrentPages(); //获取所有页面栈实例列表
                            let nowPage = pages[pages.length - 1]; //当前页页面实例
                            let prevPage = pages[pages.length - 2]; //上一页页面实例
                            prevPage.$vm.refreshflag = true

                            uni.showToast({
                                title: '添加成功',
                                success: () => {
                                    uni.navigateBack()
                                }
                            })
                        })
                    }
                }).catch(errors => {})
            }
        }
    }
</script>

<style lang="scss" scoped>
    .content {
        background: #F5F8FB;
        min-height: 100vh;
        justify-content: flex-start;
        font-family: PingFang SC;
    }

    .info-box {
        background: #fff;
        padding: 32rpx 32rpx;
        margin-top: 20rpx;
        width: 100vw;
    }

    .title {
        font-size: 28rpx;
        color: #202020;
        margin-bottom: 10rpx;
    }

    .input-box {
        font-size: 28rpx;
        width: calc(100vw - 65rpx);
    }
</style>